<template>
	<view>
		<view class="goods_list" v-if="type==='小图'">
			<view class="goods_item" v-for="item in urls" :key="item.id" @click="navigator(item.picUrl)"
				@longpress="select(item.id)">
				<image :src="item.picUrl" lazy-load="true" mode="aspectFill"
					:style="{'border': item.id===id?style:'' }"></image>
			</view>
		</view>

		<view v-for="item in picTime" :key="item.create" v-if="type==='显示时间'">
			<view
				style="height: 50rpx;background-color: #f7f7f7;margin-left: 20rpx;margin-right: 20rpx;margin-top: 50rpx;text-align: center;">
				{{item.date}}
			</view>
			<view style="margin-left: 10rpx;">
				<u-album :urls="item.urls" singleSize="180" multipleSize="83" rowCount="4" maxCount="8"></u-album>
			</view>
		</view>
		<u-picker :show="show0" @cancel="show0=false" :columns="columns" @confirm="confirm()"></u-picker>

		<u-tabbar :value="value1" @change="change1" :fixed="true" :placeholder="false" :safeAreaInsetBottom="false" v-if="id!==''&&index==='0'">
			<u-tabbar-item text="详情" icon="photo" @click="click1"></u-tabbar-item>
			<u-tabbar-item text="首页" icon="home" @click="click1"></u-tabbar-item>
			<u-tabbar-item text="移动" icon="play-right" @click="click1"></u-tabbar-item>
			<u-tabbar-item text="删除" icon="trash" @click="click1"></u-tabbar-item>
		</u-tabbar>
	</view>
</template>

<script>
	export default {
		props: ['urls', 'type', 'picTime','index'],
		data() {
			return {
				columns: [],
				show0: false,
				value1: 0,
				id: '',
				user: uni.getStorageSync("user"),
				style: '1px solid #ff0000',
				picsName: ''
			}
		},
		onLoad() {
             console.log(this.index)
		},
		methods: {
			change1(name) {
				this.value1 = name
			},
			click1(e) {
				if (e === 1) {
					uni.switchTab({
						url: '/pages/index/index'
					})
				} else if (e === 3) {
					if (this.id === '') {
						return uni.showToast({
							title: "请选择图片",
							icon: "none"
						})
					}
					this.remove(this.id)
				} else if (e === 2) {
					if (this.id === '') {
						return uni.showToast({
							title: "请选择图片",
							icon: "none"
						})
					}
					this.move(this.id)
				}

			},
			async move(id) {
				const res = await this.$myRuquest({
					url: '/wexinLogin/pic/getPics?userId=' + this.user.id,
					method: 'post',
				})
				this.columns[0] = res.data.data
				this.show0 = true
			},
			async confirm(e) {
				this.picsName = e.value
				this.show0 = false
				const res = await this.$myRuquest({
					url: '/wexinLogin/pic/movePic?id=' + this.id + '&name=' + this.picsName,
					method: 'post',
				})
				if (res.data.data === 1) {
					uni.showToast({
						title: "修改成功",
						icon: "none"
					})
				}
				this.$emit('sent', '1')
			},
			select(item) {
				if (this.id === item) {
					this.id = ''
				} else {
					this.id = item
				}
			},
			remove(item) {
				console.log(item)
				const that = this
				uni.showModal({
					title: '提示',
					content: '确定删除吗',
					success: function(res) {
						if (res.confirm) {
							uni.request({
								url: that.$baseurl + '/wexinLogin/pic/delete?userId=' + that.user.id +
									'&id=' + item,
								method: 'post',
							})
							that.$emit('sent', '1')
						} else if (res.cancel) {}

					}
				});
			},
			navigator(current) {
				uni.previewImage({
					current,
					urls: this.urls.map(item => item.picUrl)
				})
			},
			navigator2(current, item) {
				console.log(current)
				console.log(item)
				uni.previewImage({
					current,
					urls: item
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.goods_list {
		// padding: 0 15rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
        margin-left: 10rpx;

		.goods_item {
			background: #fff;
			width: 174rpx;
			padding: 5rpx;

			// box-sizing: border-box;
			image {
				width: 170rpx;
				height: 175rpx;
				display: block;
				margin: auto;
			}


			.price {
				color: $shop-color;
				font-size: 36rpx;
				margin: 20rpx 0 5rpx 0;

				text:nth-child(2) {
					color: #ccc;
					font-size: 28rpx;
					margin-left: 17rpx;
					text-decoration: line-through;
				}
			}

			.name {
				font-size: 28rpx;
				line-height: 50rpx;
				padding-bottom: 15rpx;
				padding-top: 10rpx;
			}
		}
	}
</style>
